#region 属性
const MESSAGE_PREFIX = "state_charts"
const STATE_CHART_ADDED_MESSAGE = MESSAGE_PREFIX + ":state_chart_added"
const STATE_CHART_REMOVED_MESSAGE = MESSAGE_PREFIX + ":state_chart_removed"
const STATE_UPDATED_MESSAGE = MESSAGE_PREFIX + ":state_updated"
const STATE_ENTERED_MESSAGE = MESSAGE_PREFIX + ":state_entered"
const STATE_EXITED_MESSAGE = MESSAGE_PREFIX + ":state_exited"
const TRANSITION_PENDING_MESSAGE = MESSAGE_PREFIX + ":transition_pending"
const TRANSITION_TAKEN_MESSAGE = MESSAGE_PREFIX + ":transition_fired"
const STATE_CHART_EVENT_RECEIVED_MESSAGE = MESSAGE_PREFIX + ":state_chart_event_received"
const SETTINGS_UPDATED_MESSAGE = MESSAGE_PREFIX + "_settings_updated"
const DebuggerStateInfo = preload("res://addons/State_Chart/util/editor_debugger/editor_debugger_state_info.gd")
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
static func state_chart_added(chart:StateChart):
	if not _can_send():
		return
	if not chart.is_inside_tree():
		return
	EngineDebugger.send_message(STATE_CHART_ADDED_MESSAGE,[chart.get_path()])
static func state_chart_removed(chart:StateChart):
	if not _can_send():
		return
	if not chart.is_inside_tree():
		return
	EngineDebugger.send_message(STATE_CHART_REMOVED_MESSAGE,[chart.get_path()])
static func state_updated(chart:StateChart,state:State):
	if not _can_send():
		return
	if not chart.is_inside_tree() or not state.is_inside_tree():
		return
	var transition_path:NodePath = NodePath()
	if is_instance_valid(state.pending_transition) and state.pending_transition.is_inside_tree():
		transition_path = chart.get_path_to(state.pending_transition)
	EngineDebugger.send_message(STATE_UPDATED_MESSAGE,[Engine.get_process_frames(),DebuggerStateInfo.make_array(
		chart.get_path(),
		chart.get_path_to(state),
		state.active,
		is_instance_valid(state.pending_transition),
		transition_path,
		state.pending_transition_remaining_delay,
		state
	)])
static func state_entered(chart:StateChart,state:State):
	if not _can_send():
		return
	if not chart.is_inside_tree() or not state.is_inside_tree():
		return
	EngineDebugger.send_message(STATE_ENTERED_MESSAGE,[Engine.get_process_frames(),chart.get_path(),chart.get_path_to(state)])
static func state_exited(chart:StateChart,state:State):
	if not _can_send():
		return
	if not chart.is_inside_tree() or not state.is_inside_tree():
		return
	EngineDebugger.send_message(STATE_EXITED_MESSAGE,[Engine.get_process_frames(),chart.get_path(),chart.get_path_to(state)])
static func transition_taken(chart:StateChart,source:State,transition:Transition):
	if not _can_send():
		return
	var target:State = transition.resolve_target()
	if not chart.is_inside_tree() or not source.is_inside_tree() or not transition.is_inside_tree() or target == null or not target.is_inside_tree():
		return
	EngineDebugger.send_message(TRANSITION_TAKEN_MESSAGE,[Engine.get_process_frames(), chart.get_path(), chart.get_path_to(transition), chart.get_path_to(source), chart.get_path_to(target)])
static func event_received(chart:StateChart,event:StringName):
	if not _can_send():
		return
	if not chart.is_inside_tree():
		return
	EngineDebugger.send_message(STATE_CHART_EVENT_RECEIVED_MESSAGE, [Engine.get_process_frames(), chart.get_path(), event])
static func transition_pending(chart:StateChart,source:State,transition:Transition,pending_transition_remaining_delay:float):
	if not _can_send():
		return
	if not chart.is_inside_tree() or not source.is_inside_tree() or not transition.is_inside_tree():
		return
	EngineDebugger.send_message(TRANSITION_PENDING_MESSAGE, [Engine.get_process_frames(), chart.get_path(), chart.get_path_to(source),  chart.get_path_to(transition), pending_transition_remaining_delay])
static func settings_updated(session,chart:NodePath,ignore_events:bool,ignore_transitions:bool):
	session.send_message(SETTINGS_UPDATED_MESSAGE + str(chart) + ":updated", [ignore_events, ignore_transitions])
#endregion
#region 私有方法
static func _can_send() -> bool:
	return not Engine.is_editor_hint() and OS.has_feature("editor")
#endregion
#region 生命周期函数
#endregion
